<?php
final class dbComments{
	private $o_connect;
/**
 * Constructor
 *	@param dbConnect $o_db Conexion activa
 */
	function __construct(dbConnect $o_db){
		$this->o_connect = $o_db;
	}

	function add($i_idpost, $s_user, $s_email, $s_text, $i_spam){
		if($this->error){return false;}
		$s_sql = sprintf('INSERT INTO `ablog_comments`  VALUES (null, %u, NOW(), "%.15s", "%.40s", "%.300s", %u)', $i_idpost, $s_user, $s_email, $s_text, $i_spam);
		return $this->execute($s_sql);
	}

	function nospam($i_id){
		if($this->error){return false;}
		$s_sql = sprintf('UPDATE ablog_comments SET spam = 0 WHERE ablog_comments.id_com=%d LIMIT 1', $i_id);
		return $this->execute($s_sql);
	}

	function delete($i_id){
		if($this->error){return false;}
		$s_sql = sprintf('DELETE  FROM  `ablog_comments` WHERE `ablog_comments`.`id_com`=%u', $i_id);
		return $this->execute($s_sql);
	}

	function toindex($i_idpost){
		if($this->error){return false;}
		$s_sql = sprintf('SELECT * FROM ablog_comments WHERE ablog_comments.id_post=%d ORDER BY date DESC', $i_idpost);
		return $this->execute($s_sql);
	}
}
?>
